﻿#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <netcdfcpp.h>
#include <iostream>
#include "MyNc4Parse.h"
using namespace std;

int main() {
#if 0
    NcFile dataFile("E:\\科研数据\\merra2_3d\\MERRA2_400.inst3_3d_aer_Nv.20231002.nc4", NcFile::ReadOnly);
    if (!dataFile.is_valid()) {
        cerr << "Unable to open file" << endl;
        return 1;
    }

    int numVars = dataFile.num_vars();  // 获取变量的数量
    for (int i = 0; i < numVars; ++i)
    {
        NcVar* var = dataFile.get_var(i);  // 获取第 i 个变量  
        std::string varName = var->name();  // 获取变量名
        NcType varType = var->type();
        int varDim = var->num_dims();
        //NcValues* varMes = var->values();
        std::cout << "变量名[" << i << "] = " << varName <<"   变量类型: " << varType <<"   变量维度："<< varDim << std::endl;
        
        // 读取数据
        //int arraySize = var->num_vals();
        //double* data = new double[arraySize];
        //var->get(data, arraySize);

        //// 处理数据
        //for (int i = 0; i < arraySize; ++i)
        //{
        //    std::cout << "数据[" << i << "] = " << data[i] << std::endl;
        //}

        //delete[] data;  // 释放内存

    }
    dataFile.close();
#endif
#if 0
    MyNc4Parse* obj = new MyNc4Parse();
    obj->stat2_2d_pct("MERRA2.statM_2d_pct_Nx.202210.nc4");
    delete obj;
#endif
#if 0
    MyNc4Parse* obj = new MyNc4Parse();
    Coord2Dt coordinate{
        1,-81.0,-175.0
    };
    Coord2Dt coordinate1{ coordinate };
    std::vector<Coord2Dt> coordsets;
    for (int i = 0; i < 100; i++) {
        coordinate1.lat++;
        coordinate1.lon++;
        coordsets.push_back(coordinate);
    }
    obj->stat2_2d_pct_multi("MERRA2.statM_2d_pct_Nx.202210.nc4", "PRECTOT", coordsets);
    delete obj;
#endif
#if 0
    MyNc4Parse* obj = new MyNc4Parse();
    Coord4Dt coordsets;
    coordsets.time = 180;
    coordsets.lat = -81.0;
    coordsets.lon = -175.0;
    coordsets.lev = 8.0;

    obj->inst3_3d_aer_single4d("MERRA2_400.inst3_3d_aer_Nv.20231004.nc4", "DU001", coordsets);
    delete obj;
    return 0;
#endif 
#if 1
    MyNc4Parse* obj = new MyNc4Parse("E:\\科研数据\\merra2_2d");
    vector<Coord2Dt> coordsets;
    Coord2Dt temp1 = { 1,-70.0,130.0 };
    Coord2Dt temp2 = { 1,-71.0,138.0 };
    Coord2Dt temp3 = { 1,-73.0,136.0 };
    Coord2Dt temp4 = { 1,-75.0,134.0 };
    Coord2Dt temp5 = { 1, -77.0,131.0 };
    Coord2Dt temp6 = { 1,-79.0,123.0 };
    Coord2Dt temp7 = { 1,-81.0,120.0 };
    Coord2Dt temp8 = { 1,-83.0,117.0 };
    Coord2Dt temp9 = { 1,-85.0,115.0 };
    Coord2Dt temp10 = { 1,-83.0,112.0 };
    coordsets.push_back(temp1);
    coordsets.push_back(temp2);
    coordsets.push_back(temp3);
    coordsets.push_back(temp4);
    coordsets.push_back(temp5);
    coordsets.push_back(temp6);
    coordsets.push_back(temp7);
    coordsets.push_back(temp8);
    coordsets.push_back(temp9);
    coordsets.push_back(temp10);
    vector<string> values{"BCEXTTAU","DUEXTT25","OCSCATAU","SO2CMASS","SO4CMASS","SSCMASS"};
    obj->ParseM2tmnx(values, coordsets);
    delete obj;
    return 0;
#endif
    //while (1);
    return 0;
}




